// pages/view/cl/bigprescription/bigprescription.js
const network = require('../../../../utils/network.js')
var app = getApp();
var pageSize = 0;
var startTime_n;
var endTime_n;
var cataAmount_n;
var deptId_n;
var cataId_n;
var doctorId_n;
Page({

  /**
   * 页面的初始数据
   */
  data: {

    headers: [{ text: 'recipeId', display: '处方号' }, { text: 'cataName', display: '类型' }, 
      { text: 'name', display: '病人姓名' }, { text: 'deptName', display: '科室' }, 
      { text: 'doctorCode', display: '医生号' }, { text: 'doctorName', display: '医生' },
      { text: 'inputTime', display: '处方日期' }, { text: 'amount', display: '金额' }],
    row: [],
    current: 1,
    totalPage: 1,




    //原本    
    startTime: '2018-01-01',
    endTime: '2018-01-30',
    cataAmount: 100,
    deptId: '',
    cataId: '',
    doctorId: '',
    bigCataList:[
      // {
      //   recipeId: '13627',
      //   cataName: '西药方', 
      //   name: '费云', 
      //   deptCode: '',
      //   deptName: '妇产科门诊',
      //   doctorCode: '001', 
      //   doctorName: '张晓玲', 
      //   inputTime: '2018-03-01', 
      //   amount: '143.88'
      //   },
      // {
      //   recipeId: '13628',
      //   cataName: '西药方',
      //   name: '王琦',
      //   deptCode: '',
      //   deptName: '妇产科门诊',
      //   doctorCode: '001',
      //   doctorName: '张晓玲',
      //   inputTime: '2018-03-02',
      //   amount: '118.23'
      // }
      
    ]
  },

  onChange(e) {
    console.log('onChange', e)
    this.setData({
      current: e.detail.current,
    })

    this.myRequest(e)
  },

  myRequest: function (options) {
    var that = this;
    //console.log('options:', options)
    //获得表格高度
    var windowheight = wx.getSystemInfoSync().windowHeight;
    var tdHeight = [18.4, 21.6, 39]
    if (windowheight < 550) {
      pageSize = Math.round(windowheight * 0.8 / tdHeight[0]);
    } else if (windowheight < 850) {
      pageSize = Math.round(windowheight * 0.8 / tdHeight[1]);
    } else {
      pageSize = Math.round(windowheight * 0.8 / tdHeight[2]);
    }
    console.log("每页个数", pageSize);
    //调用封装好的网络请求，获取数据
    network.get('/cl/bigprescription?startTime=' + startTime_n + '&endTime=' + endTime_n + '&cataAmount=' + cataAmount_n + '&deptId=' + deptId_n + '&cataId=' +cataId_n + '&doctorId=' + doctorId_n + '&pageCount=' + that.data.current + '&pageSize=' + pageSize, {}).then(function (res) {
      console.log('res:', res)

      that.setData({
        startTime: startTime_n,
        endTime: endTime_n,
        msg: res.data.errMsg,
        row: res.data.data,
        totalPage: res.data.totalPage
      })
      console.log('row:', that.data.row)

    }).then(function (res) {
      wx.hideLoading()
     

    }).catch(function (res) {
      console.log(res)
    })
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this
    wx.showLoading({
      title: '加载中',
    })
    console.log('options:', options)
    //保存参数值，分页使用
    startTime_n = options.startTime
    endTime_n = options.endTime
    cataAmount_n = options.cataAmount;
    deptId_n = options.deptId;
    cataId_n = options.cataId;
    doctorId_n = options.doctorId;
    that.myRequest(options)
  
  }

})